﻿using System;
using System.IO;
using System.Reflection;
using System.Text;

// <copyright file="FrameworkAssembly.cs" company="Songhay System">
//     Copyright 2008, Bryan D. Wilhite, Songhay System. All rights reserved.
// </copyright>
namespace Songhay
{
    using Models;

    /// <summary>
    /// Static members related to <see cref="System.Reflection"/>.
    /// </summary>
    public static class FrameworkAssemblyUtility
    {
        /// <summary>
        /// Returns a <see cref="System.String"/>
        /// about the executing assembly.
        /// </summary>
        /// <param name="targetAssembly">
        /// The executing <see cref="System.Reflection.Assembly"/>.
        /// </param>
        /// <returns>Returns <see cref="System.String"/></returns>
        public static string GetAssemblyInfo(Assembly targetAssembly)
        {
            return GetAssemblyInfo(targetAssembly, false);
        }

        /// <summary>
        /// Returns a <see cref="System.String"/>
        /// about the executing assembly.
        /// </summary>
        /// <param name="targetAssembly">
        /// The executing <see cref="System.Reflection.Assembly"/>.
        /// </param>
        /// <param name="useConsoleChars">
        /// When <c>true</c> selected “special” characters are formatted for the Windows Console.
        /// </param>
        /// <returns>Returns <see cref="System.String"/></returns>
        public static string GetAssemblyInfo(Assembly targetAssembly, bool useConsoleChars)
        {
            StringBuilder builder = new StringBuilder();
            FrameworkAssemblyInfo info = new FrameworkAssemblyInfo(targetAssembly);

            builder.AppendFormat("{0} {1}{2}", info.AssemblyTitle, info.AssemblyVersion, Environment.NewLine);
            builder.Append(info.AssemblyDescription);
            builder.Append(Environment.NewLine);
            builder.Append(info.AssemblyCopyright);
            builder.Append(Environment.NewLine);

            var s = builder.ToString();
            if(useConsoleChars) s = FrameworkUtility.GetConsoleCharacters(s);
            return s;
        }

        /// <summary>
        /// Gets the assembly path (excludes file name).
        /// </summary>
        /// <param name="targetAssembly">The target assembly.</param>
        /// <returns></returns>
        public static string GetAssemblyPath(Assembly targetAssembly)
        {
            return Path.GetDirectoryName(targetAssembly.Location);
        }
    }
}
